<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<!--<link rel="stylesheet" href="../../css/allApp.css" />-->
		<link rel="stylesheet" href="../../../css/css.css" />
		<style type="text/css">
			@font-face{font-family:Muiicons;font-weight:400;font-style:normal;src:url(../../../fonts/mui.ttf) format('truetype')}
			.mui-icon-search:before{content:'\e466'}
			body,
			.mui-content {
				background-color: #FFFFFF;
			}

			.mui-bar .mui-title {
				right: 80px;
				left: 80px;
			}

			.yxj-row,
			.yxj-rowxb,
			.yxj-rowxl {
				width: 92%;
				margin-left: 4%;
				padding: 10px;
				border-bottom: 1px solid #eaeaea;
				position: relative;
			}

			.marbtm {
				margin-bottom: 3px;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.colorA3A3A3 {
				color: #A3A3A3;
			}

			.color1A5186 {
				color: #1A5186;
			}

			.flex {
				display: flex;
			}

			.justcnt {
				justify-content: space-between;
			}

			.fontsize13 {
				font-size: 13px;
			}

			.fontsize14 {
				font-size: 14px;
			}

			.fontsize15 {
				font-size: 15px;
			}

			.dsh-btn {
				color: #ffffff;
				background-color: #1A5186;
				border-radius: 3px;
				width: 80px;
				padding: 3px 0px;
				text-align: center;
				position: absolute;
				right: 10px;
				top: 45px;
				font-size: 13px;
			}

			.dsh-btnlock {
				background-color: #eee;
				border: 1px solid #1A5186;
				color: #1A5186;
			}

			.dsh-btnxb {
				top: 65px;
			}

			.wifi {
				width: 80%;
				margin: 100px auto;
				text-align: center;
			}

			.wifi img {
				width: 80%;
				margin-right: 20px;
			}

			.wifi p {
				font-size: 1rem;
			}

			[v-cloak] {
				display: none;
			}

			.tabbtn {
				display: flex;
				width: 100%;
				align-items: center;
				justify-content: space-evenly;
				margin-top: 5px;
			}

			.tabbtn div {
				width: 80px;
				height: 36px;
				line-height: 36px;
				text-align: center;
				font-size: 14px;
			}

			.tabbtn .active {
				color: #1A5186;
				border-bottom: 2px solid #004A86;
			}

			.red {
				color: red
			}

			.yellow {
				color: goldenrod;
			}

			.gray {
				background-color: darkgray;
			}

			.scanfix {
				position: fixed;
				bottom: 10px;
				width: 40%;
				margin-left: 30%;
				display: none;
				text-align: center;
			}

			.line2 {
				width: 100%;
				height: 3px;
				background-color: #eaeaea;
				margin: 1px;
			}

			.mui-bar-nav,
			.mui-bar {
				box-shadow: 0px 0px 0px #ccc;
				-webkit-box-shadow: 0px 0px 0px #ccc;
			}

			.color1A5186 {
				color: #1A5186;
			}

			.xjperson {
				width: 70px;
				font-size: 14px;
				text-align: left;
			}

			.ppset {
				text-align: center;
				font-size: 14px;
				border-radius: 2px;
				width: 50px;
				height: 25px;
				line-height: 25px;
				color: #1A5186;
				border: 1px solid #1A5186
			}

			.ppshow {
				width: 100%;
				padding: 10px 10px 0;
				text-align: center;
			}

			.arrowshow {
				width: 100%;
				height: 16px;
				text-align: center;
			}

			.ppselect {
				background-color: #f7f7f7;
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.deleteme{
				position: relative;
				border: 1px solid #696C76;
				padding: 0px 7px;
				border-radius: 3px;
				margin-right: 3px;
			}
			.deleteimg{
				position: absolute;
				top: 0px;
				right: 0px;
			}
			.mtop3{
				margin-bottom: 3px;
			}
			.zhs{
				width: 100%;
				display: flex;
				justify-content: space-between;
			}
			
			.mui-search{width: 82%;margin:10px;}
			.p-search{display: flex;font-size: 14px;background-color:rgba(244, 244, 244, 1);height:54px;
			}
			.p-search input{background:#fff;}.mui-search::before{margin:-10px 0 0;}
			.p-search a{color:#09BB07;line-height:54px;height:54px;}.p-list{display: flex;}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">待巡检</h1>
		</header>
		<div class="mui-content" id="content" v-cloak>
			<div class="tabbtn">
				<div @click="getTabtn('1')" :class="tabindex == '1' ? 'active' : ''">升压站巡检</div>
				<div @click="getTabtn('2')" :class="tabindex == '2' ? 'active' : ''">设备巡检</div>
				<div @click="getTabtn('3')" :class="tabindex == '3' ? 'active' : ''">线路巡检</div>
			</div>
			<div class="line2"></div>
			<div v-if="tabindex == 1" class="mui-row yxj-row" v-for="(item,index) in data" :key="index">
				<div class="yxj-row-1" @click="getChildPage(item)">
					<div class="marbtm flex justcnt">
						<div class="marbtm fontsize15 zhs">
							<span class="fontsize15">{{changeState(item.name)}}</span>
							<span class="color1A5186 fontsize15" v-show="item.realname">执行人:{{item.realname}}</span>
						</div>
						<div v-if="item.helpstatus == '1'">
							<span class="dsh-btn" style="width: 40px;right: 60px;" @click.stop="handleTask(item,'3')">同意</span>
							<span class="dsh-btn" style="width: 40px;" @click.stop="handleTask(item,'2')">拒绝</span>
						</div>
						<div v-if="!item.helpstatus">
							<span class="dsh-btn" @click.stop="getTask(item,'1')" v-if="item.sxlstatus == '0'">{{item.status == 1 ? '开始巡检' : '巡检中'}}</span>
							<span class="dsh-btn" :class="item.status == '1' ? 'dsh-btnlock' : ''"
								v-if="item.sxlstatus == '1'">{{item.status == 1 ? '已锁定' : '巡检中'}}</span>
						</div>
					</div>
					<div class="colorA3A3A3 fontsize13">开始时间：{{item.start_time}}</div>
					<div class="colorA3A3A3 fontsize13" :class="getCheckTime(item.latestcompletetime)">
						最晚完成时间：{{item.latestcompletetime}}</div>
				</div>
				<div class="ppselect" v-show="item.status != 1 && !item.helpstatus">
					<div class="arrowshow" v-show="item.visible == 0" @click="getVisible(item,'syz')">
						<img width="16px" src="../../../img/arrowbottom.png" />
					</div>
					<div v-show="item.visible == 1"  class="ppshow">
						<div class="flex justcnt">
							<div style="width: 90%;">
								<div class="flex" style="width: 100%;">
									<div class="xjperson" style="width: 25%;">设置人员</div>
									<div style="display: flex;flex-wrap: wrap;width: 75%;">
										<div v-for="(hp,i) in item.helperList" :key="i" class="colorA3A3A3 fontsize14 deleteme mtop3" @click="deleteName(hp.id)">
											{{hp.name}}
											<img src="../../../img/delete.png" width="8px" class="deleteimg">
										</div>
									</div>
								</div>
								<div class="flex">
									<div class="xjperson">同意人</div>
									<div class="colorA3A3A3 fontsize14">{{item.agreers}}</div>
								</div>
								<div class="flex">
									<div class="xjperson">拒绝人</div>
									<div class="colorA3A3A3 fontsize14">{{item.refusers}}</div>
								</div>
							</div> 
							<div class="ppset" v-show="item.assist_button == '1'" @click="getPeople(item,1)">
								设置
							</div>
						</div>
						<img width="16px" @click="getVisible(item)" src="../../../img/arrowtop.png" />
					</div> 
				</div>
			</div>
			<div v-if="tabindex == 2">
				<form id="searchForm" target="frameFile" action="javascript:return true;" onsubmit="toSearch()">
					<div class="mui-row p-search">
						<div class="mui-input-row mui-search">
							<input adjust-position="false" v-model="form.keyword" type="search" class="mui-input-clear" id="search" placeholder="请输入" name="enterpriseName">
						</div>
						<a class="mui-navigate-left" @click="toSearch">搜索</a>
					</div>
				</form>
				
				<div class="mui-row yxj-rowxb" v-for="(item,index) in data1" :key="index">
					<div class="marbtm fontsize15 zhs">
						<span>{{item.name}}</span>	 
						<span class="color1A5186 fontsize15" v-show="item.realname">执行人:{{item.realname}}</span>
					</div>
					<div class="zhs">
						<div class="colorA3A3A3 fontsize13">编码：{{item.number}}</div>
						<div class="colorA3A3A3 fontsize13">{{getType(item.rate)}}频次</div>
					</div>
					<div class="colorA3A3A3 fontsize13">开始时间：{{item.start_time}}</div>
					<div class="colorA3A3A3 fontsize13" :class="item.ifcolor">最晚完成时间：{{item.expire_time}}</div>
					<div v-if="item.helpstatus == '1'">
						<span class="dsh-btn" style="width: 40px;right: 60px;top:60px" @click.stop="handleTask(item,'3')">同意</span>
						<span class="dsh-btn" style="width: 40px;;top:60px" @click.stop="handleTask(item,'2')">拒绝</span>
					</div>
					<div v-if="!item.helpstatus">
						<div class="dsh-btn tjbtn" :data-id="(item.id)" style="right: 100px;top: 65px;width: 60px;">跳检</div>
						<div class="dsh-btn dsh-btnxb" :class="item.sxlstatus=='1' ? 'dsh-btnlock' : ''"
							:data-lock="(item.sxlstatus)" :data-item="(JSON.stringify(item))" :data-id="(item.id)"
							:data-inspect="(item.inspect_time)">{{item.sxlstatus=='1' ? '已锁定' : (~[null,''].indexOf(item.inspect_time) ? '开始巡检' : '巡检中')}}</div>
						
					</div>
					<!-- <div class="ppselect"  v-show="item.status != 1 && !item.helpstatus"> -->
					<div class="ppselect"  v-show="item.inspect_time">
						<div class="arrowshow" v-show="item.visible == 0" @click.stop="getVisible(item,'sb')">
							<img width="16px" src="../../../img/arrowbottom.png" />
						</div>
						<div v-show="item.visible == 1" class="ppshow">
							<div class="flex justcnt">
								<div style="width: 90%;">
									<div class="flex" style="width: 100%;">
										<div class="xjperson" style="width: 25%;">设置人员</div>
										<div style="display: flex;flex-wrap: wrap;width: 75%;">
											<div v-for="(hp,i) in item.helperList" :key="i" class="colorA3A3A3 fontsize14 deleteme mtop3" @click="deleteName(hp.id)">
												{{hp.name}}
												<img src="../../../img/delete.png" width="8px" class="deleteimg">
											</div>
										</div>
									</div>
									<div class="flex">
										<div class="xjperson">同意人</div>
										<div class="colorA3A3A3 fontsize14">{{item.agreers}}</div>
									</div>
									<div class="flex">
										<div class="xjperson">拒绝人</div>
										<div class="colorA3A3A3 fontsize14">{{item.refusers}}</div>
									</div>
								</div>
								<div class="ppset"  @click="getPeople(item,2)">
									设置
								</div>
							</div>
							<img width="16px" @click.stop="getVisible(item)" src="../../../img/arrowtop.png" />
						</div>
					</div>
				</div>	
			</div>
			<div v-if="tabindex == 3" class="mui-row yxj-rowxl" v-for="(item,index) in data2" :key="index">
				<div class="yxj-row-3"  @click="getChildPage3(item)" >
					<div class="marbtm flex justcnt">
						<div class="fontsize15 marbtm"  >{{item.name}}</div>
						<div class="color1A5186 fontsize15" v-show="item.realname">执行人:{{item.realname}}</div>
						<div v-if="item.helpstatus == '1'">
							<span class="dsh-btn" style="width: 40px;right: 60px;" @click.stop="handleTask(item,'3')">同意</span>
							<span class="dsh-btn" style="width: 40px;" @click.stop="handleTask(item,'2')">拒绝</span>
						</div>
						<div v-if="!item.helpstatus">
							<span class="dsh-btn" @click.stop="getTask(item,'2')" v-if="item.sxlstatus == '0'">{{item.status == 1 ? '开始巡检' : '巡检中'}}</span>
							<span class="dsh-btn" :class="item.status == '1' ? 'dsh-btnlock' : ''"
								v-if="item.sxlstatus == '1'">{{item.status == 1 ? '已锁定' : '巡检中'}}</span>
						</div>
					</div>
					<div class="colorA3A3A3 fontsize13">开始时间：{{item.start_time}}</div>
					<div class="colorA3A3A3 fontsize13" :class="getCheckTime(item.latestcompletetime)">
						最晚完成时间：{{item.latestcompletetime}}
					</div>
				</div>
				<div class="ppselect" v-show="item.status != 1 && !item.helpstatus">
					<div class="arrowshow" v-show="item.visible == 0" @click.stop="getVisible(item,'xl')">
						<img width="16px" src="../../../img/arrowbottom.png" />
					</div>
					<div v-show="item.visible == 1" class="ppshow">
						<div class="flex justcnt">
							<div style="width: 90%;">
								<div class="flex" style="width: 100%;">
									<div class="xjperson" style="width:25%;">设置人员</div>
									<div style="display: flex;flex-wrap: wrap;width: 75%;">
										<div v-for="(hp,i) in item.helperList" :key="i" class="colorA3A3A3 fontsize14 deleteme mtop3" @click="deleteName(hp.id)">
											{{hp.name}}
											<img src="../../../img/delete.png" width="8px" class="deleteimg">
										</div>
									</div>
								</div>
								<div class="flex">
									<div class="xjperson">同意人</div>
									<div class="colorA3A3A3 fontsize14">{{item.agreers}}</div>
								</div>
								<div class="flex">
									<div class="xjperson">拒绝人</div>
									<div class="colorA3A3A3 fontsize14">{{item.refusers}}</div>
								</div>
							</div>
							<div class="ppset" v-show="item.assist_button == '1'" @click="getPeople(item,1)">
								设置
							</div>
						</div>
						<img width="16px" @click.stop="getVisible(item)" src="../../../img/arrowtop.png" />
					</div>
				</div>
			</div>
			<div class="wifi" v-if="tabindex == 1 && ifshow"><img src="./../img/empty_data.png" />
				<p>亲，这里没有数据了哦~</p>
			</div>
			<div class="wifi" v-if="tabindex == 2 && ifshow1"><img src="./../img/empty_data.png" />
				<p>亲，这里没有数据了哦~</p>
			</div>
			<div class="wifi" v-if="tabindex == 3 && ifshow2"><img src="./../img/empty_data.png" />
				<p>亲，这里没有数据了哦~</p>
			</div>
		</div>
		<div class="scanfix">
			<img src="../img/Scan.png" id="scan" style="width: 80px;height: 80px;" />
		</div>
		<script src="../../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../../js/mkeyplus.base.xunjian.js"></script>
		<script type="text/javascript" src="../../../js/vue.js"></script>
		<script type="text/javascript" src="../../../js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript">
		
			var org_code1 = '';
			var islock = false;
			// var firstdaystatus = false; //需要记住第一次天频率的状态，不然第二次天巡检无法判断
			mui.init({
				pullRefresh: {
					container: '#content',
					down: {
						style: 'circle',
						callback: pulldownRefresh
					}
				}
			});
			window.vm = new Vue({
				el: "#content",
				data: {
					data: [],
					data1: [],
					data2: [],
					tabindex: 1,
					ifshow: false,
					ifshow1: false,
					ifshow2: false,
					// firstdaystatus:false,
					listid:'',
					listtype:'',
					form:{
						keyword:''
					}
				},
				methods: {
					toSearch(){
						getDateRight('search');
					},
					deleteName(id){
						//删除人员
						plus.nativeUI.showWaiting('正在删除');
						mui.baseApp.httpRequst('/api/v2/sbxj/removeHelperUser', {
								ids:id
							},
							function(rs) {
								console.log('删除结果...'+JSON.stringify(rs));
								getData('load');
							}
						);
					},
					handleTask(item,type){
						var btnArray = ['取消', '确认'];
						mui.confirm('请确认是否协助巡检工作', '', btnArray, function(e) {
							if (e.index == 1) {
								plus.nativeUI.showWaiting('正在提交');
								mui.baseApp.httpRequst('/api/v2/sbxj/UpdateHelperStatus', {
										id:item.helperid,
										status: type
									},
									function(rs) {
										console.log('同意还是拒绝...'+JSON.stringify(rs));
										getData('load');
									}
								);
							} else {
								
							}
						})
					},
					getTask(item,type){
						if(item.status != '1'){
							return;
						}
						plus.nativeUI.showWaiting('任务领取中');
						mui.baseApp.httpRequst('/api/v2/sbxj/recieveWindXjTask', {
								xsdWindId:item.id,
								memberId: localStorage.getItem('userid')
							},
							function(rs) {
								console.log('任务领取'+JSON.stringify(rs));
								if(rs.status != 200){
									plus.nativeUI.closeWaiting();
									mui.toast(rs.message)
								}else{
									getData('load'); 
									if(type == '1'){
										var arr = plus.storage.getItem('pc') || '[]';
										arr = JSON.parse(arr);
										arr.push(item)
										plus.storage.setItem('pc', JSON.stringify(arr));
									}else{
										var arr = plus.storage.getItem('xl') || '[]';
										arr = JSON.parse(arr);
										arr.push(item)
										plus.storage.setItem('xl', JSON.stringify(arr));
									}
									vm.getChild(item,type);
								}
							}
						);
					},
					getChild(item,type){
						mui.baseApp.httpRequst('/api/v2/sbxj/notXjListByXsdWind', {
								wind:org_code1,
								xsdWindId:item.id,
								memberId:localStorage.getItem('userid')
							},
							function(res) {
								if(type == '1'){
									var arr = plus.storage.getItem('pcchild') || '[]';
									arr = JSON.parse(arr);
									arr.push({
										key:item.id,
										value:res.data
									})
									plus.storage.setItem('pcchild', JSON.stringify(arr));
								}else{
									var arr = plus.storage.getItem('xlchild') || '[]';
									arr = JSON.parse(arr);
									arr.push({
										key:item.id,
										value:res.data
									})
									plus.storage.setItem('xlchild', JSON.stringify(arr));
								}
							}
						);
					},
					getReList(type){
						var that = this;
						mui.baseApp.httpRequst('/api/v2/sbxj/findXsdWindList', {
								wind: org_code1,
								status: '1,2',
								type: type,
								memberId: localStorage.getItem('userid')
							},
							function(res) {
								if (res.status == 400) {
									mui.toast(res.message);
									return;
								}
								if (type == '1') {
									that.ifshow = false;
									if (res.data.length == 0) {
										that.ifshow = true;
									}
									console.log('频次......' + JSON.stringify(res));
									that.data = res.data;
									// for (var i = 0; i < res.data.length; i++) {
									// 	//存一个状态，只要有天巡检第1次，无论是否开始巡检，就可以判断天巡检第2次不能巡
									// 	if (res.data[i].rate == 0 && ~res.data[i].name.indexOf('天巡检第1次')) {
									// 		that.firstdaystatus = true;
									// 	}
									// }
								} else {
									that.ifshow2 = false;
									if (res.data.length == 0) {
										that.ifshow2 = true;
									}
									console.log('线路......' + JSON.stringify(res));
									that.data2 = res.data;
								}
							}
						);
					},
					getChildPage(item){
						var sbid = item.id;
						var name = item.name;
						var title = name.substring(5);
						var type = item.status;
						var rate = item.rate;
						var status = item.sxlstatus;
						console.log('status=' + status);
						
						if (status == '1' && type == '1') {
							mui.toast('巡检任务已被锁定，请先完成巡检中的任务，联系管理员解锁');
							return;
						}
						// if (rate == 0 && (firstdaystatus || vm.firstdaystatus) && ~name.indexOf('天巡检第2次')) {
						// 	mui.toast('请先巡检第一次天巡检');
						// 	return;
						// }
						if(type == '1'){
							mui.toast('请先领取任务');
							return;
						}
						mui.openWindow({
							url: 'weixunjianlist.html',
							id: 'weixunjianlist.html',
							extras: {
								sbid: sbid,
								rate: rate,
								title: title,
								scantype:item.helpstatus,
								xjtype:'pinci'
							},
							createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
						})
					},
					getChildPage3(item){
						var sbid = item.id;
						var name = item.name;
						var type = item.status;
						var rate = item.rate;
						var status = item.sxlstatus;
						console.log('status=' + status);
						if (status == '1' && type == '1') {
							mui.toast('巡检任务已被锁定，请先完成巡检中的任务，联系管理员解锁');
							return;
						}
						if(type == '1'){
							mui.toast('请先领取任务');
							return;
						}
						mui.openWindow({
							url: 'weixunjianlist.html',
							id: 'weixunjianlist.html',
							extras: {
								sbid: sbid,
								rate: rate,
								title: name,
								scantype:item.helpstatus,
								xjtype:'xianlu'
							},
							createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
						})
					},
					getPeople(item,type){
						console.log('item=',item);
						console.log('item.id=',item.id);
						this.listtype = type;
						this.listid = item.id;
						mui.openWindow({
							id: "selectpeople.html",
							url: "selectpeople.html",
							extras: {
								type: type,
								iid:item.id
							},
							waiting: {
								autoShow: false
							}
						});
					},
					getVisible(item,type) {
						item.visible = item.visible == 0 ? 1 : 0;
						if(type){
							var that = this;
							// plus.nativeUI.showWaiting();
							mui.baseApp.httpRequst('/api/v2/sbxj/findUserInfoByXjId', {
									datumId: item.id,
									type: type == 'sb' ? 2 : 1
								},
								function(res) {
									// plus.nativeUI.closeWaiting();
									item = Object.assign(item,res.data);
									that.$forceUpdate();
								}
							);
						}
					},
					getType(type) {
						var ratetext = '';
						if (type == '0') {
							ratetext = '天'
						} else if (type == '1') {
							ratetext = '周'
						} else if (type == '2') {
							ratetext = '月'
						} else if (type == '3') {
							ratetext = '季'
						} else if (type == '4') {
							ratetext = '半年'
						}
						return ratetext;
					},
					changeState: function(cs) {
						var curyear = new Date().getFullYear();
						if (cs && ~cs.indexOf(curyear)) {
							cs = curyear + cs.split(curyear)[1];
						}
						return cs;
					},
					getTabtn(index) {
						vm.tabindex = index;
						if (index == 2) {
							if(vm.ifshow1){
								document.querySelector('.scanfix').style.display = 'none';
							}else{
								document.querySelector('.scanfix').style.display = 'block';
							}
						} else {
							document.querySelector('.scanfix').style.display = 'none';
						}
					},
					getCheckTime(d) {
						var curd = new Date().getTime();
						var actived = 0;
						if (d) {
							actived = new Date(Date.parse(d)).getTime();
							if (actived < curd) {
								return 'red'
							}
							if (actived - curd < 86400000) {
								return 'yellow'
							}
						}
						return 'normal';
					}
				}
			});
			
			//跳检
			$(".mui-content").on("tap", ".tjbtn", function() {
				var id = $(this).attr('data-id');
				dataArr.push(id);
				mui.openWindow({
					id: "reason.html",
					url: "reason.html",
					waiting: {
						autoShow: false, //自动显示等待框，默认为true
					},
					extras: {
						Idarr: dataArr,
						xjtype:'shebei',
						xsdwindid:''
					}
				});
			})
			
			mui.plusReady(function() {
				var org_code = localStorage.getItem('org_code'); //获取缓存中的风场编号
				org_code1 = JSON.parse(org_code);
				console.log('org_code1', org_code1);
				checkLock(); //检查列表是否被锁定
				// initData();//初始化数据
				// getListChild(); //初始化点击事件
				getListChildSb(); //初始化点击事件
				// getPeople();//选人初始化
				
			})

			function checkLock() {
				plus.nativeUI.showWaiting();
				mui.baseApp.httpRequst('/api/v2/sbxj/findWindLockStatus', {
						wind: org_code1
					},
					function(res) {
						console.log('temp......' + JSON.stringify(res));
						islock = res.data.lockStatus;
						initData(); //初始化数据
					}
				);
			}

			function initData() {
				getDateLeft('1','loadinit');
				getDateLeft('2');
				getDateRight();
			}

			function getData(load) {
				if (vm.tabindex == '1') {
					getDateLeft('1',load);
				} else if (vm.tabindex == '3') {
					getDateLeft('2',load);
				} else {
					getDateRight(load);
				}
			}

			function getDateLeft(type,load) {
				mui.baseApp.httpRequst('/api/v2/sbxj/findXsdWindList', {
						wind: org_code1,
						status: '1,2',
						type: type,
						memberId: localStorage.getItem('userid')
					},
					function(res) {
						if(load == 'loadinit'){
							setTimeout(()=>{
								plus.nativeUI.closeWaiting();
							},500)
						}
						if(load == 'load'){
							plus.nativeUI.closeWaiting();
						}
						if (res.status == 400) {
							mui.toast(res.message);
							return;
						}
						if (type == '1') {
							vm.ifshow = false;
							if (res.data.length == 0) {
								vm.ifshow = true;
							}
							console.log('频次......' + JSON.stringify(res));
							vm.data = res.data;
							// for (var i = 0; i < res.data.length; i++) {
							// 	//存一个状态，只要有天巡检第1次，无论是否开始巡检，就可以判断天巡检第2次不能巡
							// 	if (res.data[i].rate == 0 && ~res.data[i].name.indexOf('天巡检第1次')) {
							// 		firstdaystatus = true;
							// 	}
							// }
						} else {
							vm.ifshow2 = false;
							if (res.data.length == 0) {
								vm.ifshow2 = true;
							}
							console.log('线路......' + JSON.stringify(res));
							vm.data2 = res.data;
						}
					}
				);
			}

			function getDateRight(load) {
				mui.baseApp.httpRequst('/api/v2/sbxj/findDeviceTaskList', {
						wind: org_code1,
						memberId: localStorage.getItem('userid'),
						name:vm.form.keyword
					},
					function(rs) {
						if(load == 'load'){
							plus.nativeUI.closeWaiting();
						}
						if(load == 'search'){
							vm.data1 = []
						}
						vm.ifshow1 = false;
						console.log('设备.....'+JSON.stringify(rs.data));
						var res = rs.data;
						if (res.length == 0) {
							vm.ifshow1 = true;
							document.querySelector('.scanfix').style.display = 'none';
						}
						for (var i = 0; i < res.length; i++) {
							res[i].ifcolor = getCheckTime(res[i].expire_time);
							res[i].islock = String(~[null, ''].indexOf(res[i].inspect_time) && islock);
						}
						vm.data1 = res;
					}
				);
			}
			/**
			 * 下拉刷新具体业务实现
			 */
			function pulldownRefresh() {
				getData()
				setTimeout(function() {
					mui('#content').pullRefresh().endPulldownToRefresh();
				}, 1000);
			}

			//扫码
			document.querySelector('#scan').addEventListener('tap', function() {
				mui.openWindow({
					id: "codersb.html",
					url: "codersb.html",
					extras: {
						// type: rate,
						// xsdwindid:xsdwindid
					},
					waiting: {
						autoShow: false
					}
				});
			})

			function getListChildSb() {
				$('#content').on('tap', '.dsh-btnxb', function() {
					var lock = $(this).attr('data-lock');
					var inspect = $(this).attr('data-inspect');
					var id = $(this).attr('data-id');
					var item = $(this).attr('data-item'); 
					if (inspect) {
						mui.toast('请扫码巡检');
						return;
					}
					if (lock == '1') {
						mui.toast('巡检任务已被锁定，请先完成巡检中的任务，联系管理员解锁');
						return;
					}
					plus.nativeUI.showWaiting('任务领取中');
					mui.baseApp.httpRequst('/api/v2/sbxj/recieveSbXjTask', {
							id: id,
							memberId: localStorage.getItem('userid')
						},
						function(res) {
							console.log('res=' + JSON.stringify(res));
							if(res.status != 200){
								mui.toast(res.message);
								plus.nativeUI.closeWaiting();
								return;
							}
							getDateRight('load');
							var arr = plus.storage.getItem('sb') || '[]';
							arr = JSON.parse(arr);
							arr.push(JSON.parse(item));
							plus.storage.setItem('sb', JSON.stringify(arr));
						}
					);

				});
			}
			//当前时间大于开始时间，才能巡检
			function getCheckIfClick(d) {
				var curd = new Date().getTime();
				var newd = 0;
				if (d) {
					newd = new Date(Date.parse(d)).getTime();
				}
				return curd > newd ? 'true' : 'false';
			}
			//判断结束时间是否大于当前时间
			function getCheckTime(d) {
				var curd = new Date().getTime();
				var actived = 0;
				if (d) {
					actived = new Date(Date.parse(d)).getTime();
					if (actived < curd) {
						return 'red'
					}
					if (actived - curd < 86400000) {
						return 'yellow'
					}
				}
				return 'normal';
			}
			
			function setPeoples(persons){
				plus.nativeUI.showWaiting('设置人员中');
				mui.baseApp.httpRequst('/api/v2/sbxj/setXsdHelperUser', {
						datumId: vm.listid,
						type: vm.listtype,
						helperIds: persons
					},
					function(res) {
						console.log('res=' + JSON.stringify(res));
						getData('load');
					}
				);
			}

			window.addEventListener('refresh', function(e) { //执行刷新
				// firstdaystatus = false;
				getData();
			});
			
			window.addEventListener('refresh1', function(e){//执行刷新
				var persons = e.detail.persons;
				persons = persons.join(',');
				if(persons != ''){
					setPeoples(persons);
				}
			})
			
			function toSearch(){
				getDateRight('search');
				
			}
		</script>
	</body>

</html>
